<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>ECharts</title>
	<!-- 引入刚刚下载的 ECharts 文件 -->
	<script th:src="@{/static/jquery-2.1.4.js}" type="text/javascript" charset="utf-8"></script>
	<script th:src="@{/static/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
	<script th:src="@{/static/mylayer.js}" type="text/javascript" charset="utf-8"></script>
	<script th:src="@{/static/echarts.min.js}" type="text/javascript" charset="utf-8"></script>

</head>
<body>
	<!-- 为 ECharts 准备一个定义了宽高的 DOM -->
	<div id="main" style="width: 600px;height:400px;"></div>
	<script type="text/javascript">
		// 基于准备好的dom，初始化echarts实例
		var myChart = echarts.init(document.getElementById('main'));

		$.post(
			'/echarts/selectDeptCount',
			function (result) {
				console.log(result);
				console.log(result.data);
				// [{name: '软件部', value: 2},{name: '硬件部', value: 3}]
				var xArray = new Array();
				var yArray = new Array();
				var array = result.data;
				for (var i = 0; i < array.length; i++) {
					//{name: '软件部', value: 2}
					xArray.push(array[i].name);
					yArray.push(array[i].value);
				}
				// 指定图表的配置项和数据
				var option = {
					title: {
						text: 'ECharts 入门示例'
					},
					tooltip: {},
					legend: {
						data: ['销量']
					},
					xAxis: {
						data: xArray
					},
					yAxis: {},
					series: [
						{
							name: '销量',
							type: 'bar',
							data: yArray
						}
					]
				};

				// 使用刚指定的配置项和数据显示图表。
				myChart.setOption(option);
			},
			'json'
		);


	</script>
</body>
</html>